#!/bin/sh -e
#
# zzz-sysupgrade
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

SYSUPGRADE_WORK_DIR=/etc/kpc/sysupgrade/guest

sysupgrade_file="$SYSUPGRADE_WORK_DIR/yandi-sys-upgrade.sh"
sysupgrade_bak="${sysupgrade_file}_bak"
sysupgrade_done="${sysupgrade_file}_done"
sysupgrade_lock="${sysupgrade_file}_lock"

# System upgrade script
if [ -x $sysupgrade_file ]; then
  if [ -f $sysupgrade_done ]; then
    mv -f $sysupgrade_file $sysupgrade_bak
  else
    (flock -x $sysupgrade_lock -c "$sysupgrade_file")&
  fi
fi

exit 0
